package com.hr.two;

/**
 * @author ：zhz
 * @date ：Created in 2021/03/01
 * @version: V1.0
 * @slogan: 天下风云出我辈，一入代码岁月催
 * @description:
 **/
public class JZ5_替换空格 {
    public String replaceSpace(String s) {
        return s.toString().replaceAll(" ", "%20");//将空格替换成%20
    }
    public String replaceSpace2(String s) {
        char[] c = s.toCharArray();
        StringBuffer sb=new StringBuffer();
        for (int i = 0; i < c.length; i++) {
            if (c[i]==' '){
                sb.append("%20");
            }else{
                sb.append(c[i]);
            }
        }
        return sb.toString();
    }
}
